{extend name="../../base/view/common/base" /}

{block name="body"}
<div class="p-page">
    <form class="layui-form" lay-filter="form">
        <input type="hidden" name="id" value="{$detail.id|default='0'}">

        <div class="layui-form-item">
            <label class="layui-form-label">类型名称</label>
            <div class="layui-input-block">
                <input type="text" name="name" value="{$detail.name|default=''}" lay-verify="required" lay-reqText="请输入节点类型名称" placeholder="请输入节点类型名称" class="layui-input" autocomplete="off">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">案件类型</label>
            <div class="layui-input-block">
                <select name="case_type" lay-verify="required" lay-reqText="请选择案件类型">
                    <option value="">请选择案件类型</option>
                    {foreach $caseTypes as $key => $type}
                    <option value="{$key}" {if isset($detail.description) && $detail.description == $key}selected{/if}>{$type}</option>
                    {/foreach}
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">排序</label>
            <div class="layui-input-block">
                <input type="number" name="sort" value="{$detail.sort|default='100'}" lay-verify="number" placeholder="请输入排序" class="layui-input" autocomplete="off">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveForm">保存</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
{/block}

{block name="js"}
<script>
const moduleInit = ['tool'];
function gouguInit() {
    let tool = layui.tool,
        form = layui.form;

    //监听提交
    form.on('submit(saveForm)', function(data){
        let url = data.field.id > 0 ? '/lawcase/nodetype/edit' : '/lawcase/nodetype/add';

        tool.post(url, data.field, function(res){
            console.log('保存节点类型响应:', res); // 添加调试日志
            if (res.code === 0) {
                layer.msg(res.msg || '保存成功', {icon: 1});
                tool.sideClose(1000); // 延迟1秒关闭
            } else {
                layer.msg(res.msg || '保存失败', {icon: 2});
            }
        });
        return false;
    });
}
</script>
{/block}